﻿using System;
using System.Web.UI;
using SouthernLand.Common;
using SouthernLand.Common.Untilities;

namespace SouthernLand.WebMaster
{
    public partial class Contents : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (dlContents.SelectedItem.Value != "")
                {
                    int ContentID = ConvertUtility.ToInt32(dlContents.SelectedItem.Value);
                    Common.BOL.Content.Contents obj = Common.BOL.Content.Contents.GetContentsByID(ContentID);
                    txtNContent.Value = obj.Content;
                    txtNContent_en.Value = obj.Content_en;
                }
            }
        }

        protected void dlContents_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (dlContents.SelectedItem.Value != "")
            {
                int ContentID = ConvertUtility.ToInt32(dlContents.SelectedItem.Value);
                Common.BOL.Content.Contents obj = Common.BOL.Content.Contents.GetContentsByID(ContentID);
                txtNContent.Value = obj.Content;
                txtTitle.Text = obj.Title;

                txtTitle_en.Text = obj.Title_en;
                txtNContent_en.Value = obj.Content_en;
            }
        }

        protected void btSave_Click(object sender, EventArgs e)
        {
            if (dlContents.SelectedItem.Value != "")
            {
                int ContentID = ConvertUtility.ToInt32(dlContents.SelectedItem.Value);
                var obj = new Common.BOL.Content.Contents();
                obj.ContentID = ContentID;
                obj.Title = txtTitle.Text;
                obj.Content = txtNContent.Value;

                obj.Title_en = txtTitle_en.Text;
                obj.Content_en = txtNContent_en.Value;

                Common.BOL.Content.Contents.Update(obj);

                PanelMsg.Visible = true;
                lblMsg.Text = "Cập nhật thông tin thành công";
            }
        }
    }
}